<?php

include '../koneksi/Koneksi.php';

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
$koneksi = new Koneksi();
$koneksi->koneksiDB();
// Create table
$sql1 = "create table kategori (id_kategori varchar(3) not null unique, "
        . "nama_kategori varchar(25) not null unique, "
        . "primary key (id_kategori))";
// Execute query
if (mysql_query($sql1)) {
    echo "Table kategori created successfully";
} else {
    echo "Error creating table:" . mysql_error();
}
echo '</br>';
$sql2 = "create table provinsi (id_provinsi varchar(2) not null unique, "
        . "nama_provinsi varchar(25) not null, "
        . "primary key (id_provinsi))";
if (mysql_query($sql2)) {
    echo "Table provinsi created successfully";
} else {
    echo "Error creating table:" . mysql_error();
}
echo '</br>';
$sql4 = "create table kabupaten (id_kabupaten varchar(4) not null unique, "
        . "nama_kabupaten varchar(50) not null, "
        . "id_provinsi varchar(2), "
        . "primary key (id_kabupaten), "
        . "foreign key (id_provinsi) references provinsi(id_provinsi))";
if (mysql_query($sql4)) {
    echo "Table kabupaten created successfully";
} else {
    echo "Error creating table:" . mysql_error();
}
echo '</br>';
$sql6 = "create table pengguna (id_pengguna varchar(12) not null unique, "
        . "password varchar(255) not null, "
        . "nama_pengguna varchar(50) not null, "
        . "email_pengguna varchar(100) not null unique, "
        . "no_telp varchar(20) not null, "
        . "pin_BB varchar(10), "
        . "alamat varchar(100), "
        . "tgl_lahir varchar(10), "
        . "jenis_kelamin varchar(1), "
        . "foto varchar(300), "
        . "id_kabupaten varchar(4), "
        . "key_confirm varchar(255), "
        . "primary key (id_pengguna), "
        . "foreign key (id_kabupaten) references kabupaten(id_kabupaten))";
if (mysql_query($sql6)) {
    echo "Table pengguna created successfully";
} else {
    echo "Error creating table:" . mysql_error();
}
echo '</br>';
$sql8 = "create table barang (id_barang varchar(25) not null unique, "
        . "nama_barang varchar(50) not null, "
        . "deskripsi varchar(200) not null, "
        . "tgl_unggah datetime not null, "
        . "tgl_expired datetime not null, "
        . "status varchar(16) not null, "
        . "id_kategori varchar(3), "
        . "id_provinsi varchar(2), "
        . "id_pengguna varchar(12), "
        . "primary key (id_barang), "
        . "foreign key (id_kategori) references kategori(id_kategori), "
        . "foreign key (id_provinsi) references provinsi(id_provinsi), "
        . "foreign key (id_pengguna) references pengguna(id_pengguna))";
if (mysql_query($sql8)) {
    echo "Table barang created successfully";
} else {
    echo "Error creating table:" . mysql_error();
}
echo '</br>';
$sql9 = "create table komentar (id_komentar varchar(10) not null unique, "
        . "komentar varchar(150) not null, "
        . "tgl_komentar datetime not null, "
        . "id_pengguna varchar(12), "
        . "id_barang varchar(25), "
        . "primary key (id_komentar), "
        . "foreign key (id_pengguna) references pengguna(id_pengguna), "
        . "foreign key (id_barang) references barang(id_barang))";
if (mysql_query($sql9)) {
    echo "Table komentar created successfully";
} else {
    echo "Error creating table:" . mysql_error();
}
echo '</br>';
$sql10 = "create table testimoni (id_testimoni varchar(15) not null unique, "
        . "pesan varchar(200) not null, "
        . "id_pengguna varchar(12), "
        . "tgl_testimoni datetime not null, "
        . "primary key (id_testimoni), "
        . "foreign key (id_pengguna) references pengguna(id_pengguna))";
if (mysql_query($sql10)) {
    echo "Table testimoni created successfully";
} else {
    echo "Error creating table:" . mysql_error();
}
echo '</br>';
$sql12 = "create table gambar (id_gambar varchar(25) not null unique, "
        . "url_gambar_asli varchar(200) not null, "
        . "url_gambar_tumbnail varchar(200) not null, "
        . "id_barang varchar(25), "
        . "primary key (id_gambar), "
        . "foreign key (id_barang) references barang(id_barang))";
if (mysql_query($sql12)) {
    echo "Table gambar created successfully";
} else {
    echo "Error creating table:" . mysql_error();
}
echo '</br>';
$sql11 = "create table inspiratif (id_inspiratif varchar(5) not null unique, "
        . "pesan varchar(200) not null, "
        . "tgl_update varchar(10), "
        . "status varchar(2), "
        . "author varchar(25), "
        . "primary key (id_inspiratif))";
if (mysql_query($sql11)) {
    echo "Table inspiratif created successfully";
} else {
    echo "Error creating table:" . mysql_error();
}

